import Vue from 'vue/dist/vue.esm'

// Vue.config.productionTip = false
// Vue.config.devtools = false

globalThis.Vue = Vue



import 'scrollable-component';

import VueClipboard from 'vue-clipboard2'

VueClipboard.config.autoSetContainer = true // add this line
Vue.use(VueClipboard)
import ELEMENT2 from 'element-ui'

import './lan.js'

import locale from '../babel-static/zh-CN'


Vue.use(ELEMENT2, { size: 'small', zIndex: 3000, locale });
globalThis.ELEMENT = ELEMENT2

// globalThis.ELEMENT = installElement(Vue, Vue, globalThis.$ELEMENT_OPTIONS)

import './app.scss';
import App from './App.vue'

import 'element-ui/lib/theme-chalk/index.css';
// import '@/index.scss'
import './styles/demo-page.scss'




import   VueCompositionPlugin, * as Lib from "@vue/composition-api";



import './components/CodeMirror/init'


import '../static/initGlo'
import '../static/assets/index.css'


import  {initZPkgs} from '../src/main.js'
import {installExtCom} from '../src/com.js'
import {installExtPage} from '../src/page.js'

import {useFetchDataSource} from "../babel-static/hooks";

initZPkgs(Vue, function ({initZForm} = {}) {
  installExtCom(Vue);
  installExtPage(Vue);
  initZForm(Vue, Vue, {
    request: {
      async ['fetch']({apiConfig, type, ctx} = {}) {
        // console.log('fetch', apiConfig, ctx)
        let dataFetchHandle = useFetchDataSource()

        if (type === 'options') {
          // let {config = {}, ui, url} = apiConfig
          // console.log(ui)

          let [reqOption, ajaxOption] = dataFetchHandle.initReq(apiConfig, {
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NTI2Njc3NjIsInVzZXJuYW1lIjoiYWRtaW4ifQ.cdLogd4vrhLyLYYKurBmukEhBZGGDhWS_GhQbtMEKvg'
          })

          // if (reqOption.url.indexOf('zy-boot') < 0) {
          //   reqOption.url = '/api' + apiConfig.url
          // }

          let res = await dataFetchHandle.req({reqOption, ajaxOption})
          return res
        }
        return []
      },
    }
  })
}, {
  ELEMENT: ELEMENT2,
  Lib,
  VueCompositionPlugin,
})

import VueRouter from 'vue-router'
Vue.use(VueRouter)

import {initRequestLib, context} from './plugins/z-request';
let { request }  = initRequestLib({
  ajaxConfig: {
    baseURL: ''
  },
  getToken() {
    return 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NTUxNzIxNzUsInVzZXJuYW1lIjoiYWRtaW4ifQ.p8WNj7BiSAAWG9CUkRH2lTKqdR-8EvpU2SdFyTOQCaY'
  }
});
context.Message = function (...args) {
  globalThis.ELEMENT.Message(...args)
}
globalThis.Req = request;

import {routes} from "./router/routes";

// 3. 创建 router 实例，然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
const router = new VueRouter({
  routes // (缩写) 相当于 routes: routes
})

let app = new Vue({
  router,
  render: h => h(App)
}).$mount('#app');
